package com.indigon.parkStory.view
{
	import com.indigon.parkStory.model.GameEvent;
	import com.indigon.parkStory.model.ModelMain;
	import com.indigon.parkStory.model.objects.LillyModel;
	import com.indigon.utils.SoundManager;

	public class SoundMain
	{
		public static const SFX_Jump  			: Array = [SFX_Frog1, SFX_Frog2, SFX_Frog3, SFX_Frog4, SFX_Frog5, SFX_Frog6];
		public static const SFX_Combo 			: Array = [SFX_Combo1, SFX_Combo2, SFX_Combo3, SFX_Combo4, SFX_Combo5, SFX_Combo6, SFX_Combo7, SFX_Combo8, SFX_Combo9, SFX_Combo10, SFX_Combo11, SFX_Combo12];
		public static const SFX_Star  			: Array = [SFX_Star1, SFX_Star2, SFX_Star3];
		public static const SFX_StarLevel   	: Array = [SFX_StarLevel1, SFX_StarLevel2, SFX_StarLevel3];
		public static const SFX_StarBadLevel 	: Array = [null, SFX_StarBadLevel2, SFX_StarBadLevel3];
		
		private var _model : ModelMain;
		private var _snd : SoundManager;
		
		public function SoundMain(model:ModelMain)
		{
			this._model = model;
			this._snd = SoundManager.instance;
		}
		
		public function start():void
		{
			_snd.playMusicByClass(SFX_Loop, 0.5, 99999);
		}
		
		public function end():void
		{
			_snd.stopMusic();
		}
		
		public function update():void
		{
			var events : Vector.<GameEvent> = _model.events;
			for each (var event : GameEvent in events)
			{
				switch (event.type)
				{
					case GameEvent.LILLY_FADE 		: 
					{
						_snd.playSoundByClass(SFX_Fade);
						_snd.playSoundByClass(SFX_Drown);
						break;
					}
					case GameEvent.LILLY_SINGLE 		: 
					{
						_snd.playSoundByClass(SFX_SingleDrown);
						break;
					}
					case GameEvent.JUMP_FAIL  		: 
					{
						_snd.playSoundByClass(SFX_Drown);
						break;
					}
					case GameEvent.JUMP_START 		: 
					{
						_snd.playRandomSound(SFX_Jump);
						_snd.playSoundByClass(SFX_JumpWhoosh, 0.3);
						break;
					}
					case GameEvent.JUMP_SUCCESS 	: 
					{
						var lilly : LillyModel = LillyModel(event.object);
						_snd.playSoundByClass(lilly.data.isStatic ? SFX_LandSolid : SFX_Land);
						if (lilly.data.isTurtle)
						{
							_snd.playSoundByClass(SFX_Turtle, 1.3);
						}
						else if (lilly.data.isCarrier)
						{
							_snd.playSoundByClass(SFX_FrogCarrier);
						}
						break;
					}
					case GameEvent.LILLY_COLLISION 	: 
					{
						_snd.playSoundByClass(SFX_Lilly);
						break;
					}
					case GameEvent.STAR_COLLECTED 	: 
					{
						_snd.playSoundByClass(SFX_Star[_model.score.collectedStars - 1]);
						break;
					}
					case GameEvent.GOAL_COLLECTED   :
					{
						_snd.playSoundByClass(SFX_Combo[Math.min(_model.score.combo - 1, SFX_Combo.length - 1)]);
						break;
					}
					case GameEvent.RESET_COMBO	   :
					{
						_snd.playSoundByClass(SFX_Combo[Math.min(_model.score.combo - 1, SFX_Combo.length - 1)]);
						break;
					}
					case GameEvent.WIN_LEVEL		:
					{
						_snd.playSoundByClass(SFX_Win);
						break;
					}
					case GameEvent.LOSE_LEVEL		:
					{
						_snd.playSoundByClass(SFX_Lose);
						break;
					}
				}
			}
		}
	}
}